package com.wugh.fast.kernel.core.exception;

import com.wugh.fast.kernel.core.enums.EnumInterface;
import com.wugh.fast.kernel.core.enums.FastExceptionEnum;
import lombok.Getter;

/**
 * 说明: 全局默认业务异常
 * <pre>
 *     通过业务枚举快速抛出业务异常
 * </pre>
 *
 * @author wugh
 * @date 2019-01-24 17:00
 */
public class FastBusinessException extends FastAbstractException {
    private static final EnumInterface<Integer> DEFAULT_EXCEPTION_ENUM = FastExceptionEnum.GLOBAL_BUSINESS_EXCEPTION;
    @Getter
    private EnumInterface<Integer> exceptionEnum;

    public FastBusinessException(Integer code, String msg) {
        this.exceptionEnum = new EnumInterface<Integer>() {
            @Override
            public Integer getCode() {
                return code;
            }

            @Override
            public String getDesc() {
                return msg;
            }
        };
    }

    public FastBusinessException(EnumInterface<Integer> exceptionEnum) {
        this.exceptionEnum = exceptionEnum;
    }

    public FastBusinessException(String message, EnumInterface<Integer> exceptionEnum) {
        super(message);
        this.exceptionEnum = exceptionEnum;
    }

    public FastBusinessException(String message, Throwable cause, EnumInterface<Integer> exceptionEnum) {
        super(message, cause);
        this.exceptionEnum = exceptionEnum;
    }

    public FastBusinessException(Throwable cause, EnumInterface<Integer> exceptionEnum) {
        super(cause);
        this.exceptionEnum = exceptionEnum;
    }

    public FastBusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace, EnumInterface<Integer> exceptionEnum) {
        super(message, cause, enableSuppression, writableStackTrace);
        this.exceptionEnum = exceptionEnum;
    }

    public FastBusinessException() {
        this(DEFAULT_EXCEPTION_ENUM);
    }

    public FastBusinessException(String message) {
        this(message, DEFAULT_EXCEPTION_ENUM);
    }

    public FastBusinessException(String message, Throwable cause) {
        this(message, cause, DEFAULT_EXCEPTION_ENUM);
    }

    public FastBusinessException(Throwable cause) {
        this(cause, DEFAULT_EXCEPTION_ENUM);
    }

    public FastBusinessException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        this(message, cause, enableSuppression, writableStackTrace, DEFAULT_EXCEPTION_ENUM);
    }
}
